﻿using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class TestMySQL : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string connStr = "server=localhost;user=study;password=123;database=test";
        MySqlConnection conn = new MySqlConnection(connStr);
        try
        {
            conn.Open();
            Literal1.Text = "数据库连接成功！";

        }
        catch (MySqlException ex)
        {
            Debug.WriteLine(ex.Number + ":" + ex.Message);
            Literal1.Text = "数据库未知错误";
        }
        finally
        {
            if (conn != null)
            {
                conn.Close();
            }
        }


    }
}